
#include "plugin_common.h"
#include "plugin_manager.h"

/*
 * 初始化导出模块
 */
static napi_value Init(napi_env env, napi_value exports) {
    napi_property_descriptor desc[] = {
        //        DECLARE_NAPI_FUNCTION("getContext", PluginManager::GetContext),
        {"getContext", nullptr, PluginManager::GetContext, nullptr, nullptr, nullptr, napi_default, nullptr}};
    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);

    bool ret = PluginManager::GetInstance()->Export(env, exports);
    if (!ret) {
        LOGE("init fail");
    }
    return exports;
}

/*
 * Napi模块定义
 */
static napi_module nativerenderModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = Init, // called by ACE XComponent
    .nm_modname = "nativerender",
    .nm_priv = ((void *)0),
    .reserved = {0},
};

/*
 * 模块注册
 */
extern "C" __attribute__((constructor)) void RegisterModule(void) {
    napi_module_register(&nativerenderModule);
}